import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author HuRui
 * create on 2018/12/23 16:07
 */
public class DataUtil {
    private DataUtil(){}

    /**
     * 获取指定区间的len长度的数组
     * @param len
     * @param min
     * @param max
     * @return
     */
    public static Integer[] randomArray(int len, int min, int max) {
        Integer[] arr = new Integer[len];
        for (int i = 0; i < len; i++) {
            arr[i] = (int) (Math.random() * (max - min + 1) + min);
        }
        return arr;
    }

    /**
     * 打印数组
     * @param arr
     */
    public static void printArray(Integer[] arr) {
        if (arr == null || arr.length == 0) {
            return;
        }
        int len = arr.length;
        System.out.println();
        for (int i = 0; i < len; i++) {
            if (i == len - 1) {
                System.out.println(arr[i]);
            }else {
                System.out.print(arr[i]+",");
            }
        }
        System.out.println();
        List<String> list = Collections.synchronizedList(new ArrayList<>());
    }

    public static void copyArray(Integer[] src, Integer[] des) {
        System.arraycopy(src,0,des,0,src.length);
    }

    /**
     * 交换指定数组中指定位置的两个元素位置
     * @param arr
     * @param firstIndex
     * @param secondIndex
     */
    public static void swap(int[] arr, int firstIndex, int secondIndex) {
        if (arr == null || arr.length == 0) {
            return;
        }
        if (firstIndex < 0 || secondIndex < 0) {
            return;
        }
        int len = arr.length;
        if (firstIndex > len || secondIndex > len) {
            return;
        }
        int tmp = arr[firstIndex];
        arr[firstIndex] = arr[secondIndex];
        arr[secondIndex] = tmp;
    }

    /**
     * 交换指定数组中指定位置的两个元素位置
     * @param arr
     * @param firstIndex
     * @param secondIndex
     */
    public static void swap(Comparable[] arr, int firstIndex, int secondIndex) {
        if (arr == null || arr.length == 0) {
            return;
        }
        if (firstIndex < 0 || secondIndex < 0) {
            return;
        }
        int len = arr.length;
        if (firstIndex > len || secondIndex > len) {
            return;
        }
        Comparable tmp = arr[firstIndex];
        arr[firstIndex] = arr[secondIndex];
        arr[secondIndex] = tmp;
    }

    /**
     * 交换指定数组中指定位置的两个元素位置
     * @param arr
     * @param firstIndex
     * @param secondIndex
     */
    public static void swap(List<Comparable> arr, int firstIndex, int secondIndex) {
        if (arr == null || arr.size() == 0) {
            return;
        }
        if (firstIndex < 0 || secondIndex < 0) {
            return;
        }
        int len = arr.size();
        if (firstIndex > len || secondIndex > len) {
            return;
        }
        Comparable tmp = arr.get(firstIndex);
        arr.set(firstIndex,arr.get(secondIndex));
        arr.set(secondIndex, tmp);
    }
}
